package com.shen.utils;

import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;

public class MacUtils {

	public static String getMac() {
		List<String> macs = new ArrayList<String>();
		try {
			Process process = Runtime.getRuntime().exec("ipconfig /all");
			InputStreamReader ir = new InputStreamReader(process.getInputStream());
			LineNumberReader input = new LineNumberReader(ir);
			String line;
			while ((line = input.readLine()) != null)
				if (line.indexOf("Physical Address") > 0) {
					String MACAddr = line.substring(line.indexOf("-") - 2);
					macs.add(MACAddr);
//					System.out.println(Arithmetic.getEncString(MACAddr));
//					System.out.println("MAC address = [" + MACAddr + "]");
				}
		} catch (java.io.IOException e) {
			System.err.println("IOException " + e.getMessage());
		}
		return macs.get(0);
	}
	
	public static void main(String[] args){
		MacUtils.getMac();
	}
}